#include <iostream>
using namespace std;
const int N = 100050;
int p[N];
int find(int x){
	if (p[x] != x) p[x] = find(p[x]);
	return p[x];
}
int n, m;

int main(){
	cin >> n >> m;
	for (int i = 0; i <= n; i ++){ p[i] = i;}
	while (m--) {
		char c;
		int a, b;
		cin >> c >> a >> b;
		if (c == 'M'){
			if (find(a) != find(b)){
				p[(find(a))] = find(b);
			}
		} else {
			if (find(a) == find(b)){
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}
	}
	return 0;
}
